<template>
  <div class="newsurvey-data">
    <el-card style="position: relative;">
      <div slot="header">
        <tools-btn
          :toolsData="toolsData"
          @addData="addData"
          @refresh="refresh"
          @search="search"
          @fieldSet="fieldSet"
          @hasOperation="hasOperation"
        />
        <el-upload
          class="upload-demo"
          action=""
          :on-success="fileSuccess"
          multiple
          style="position: absolute;top: 15px;right: 20px;width:75px;"
          >
          <el-button size="mini" type="primary">点击上传</el-button>
        </el-upload>
      </div>
      <table-list
        id="tableExcel"
        :table="table"
        ref="tableList"
        @handleEdit="handleEdit"
        @handleSee="handleSee"
      >
        <template
          slot-scope="props"
          slot="checkStatus"
        >
          <span :style="{'color':props.obj.row.checkStatus=='0'?'red':'#67C23A'}"
            v-text="props.obj.row.checkStatus === '0' ? '未调查' : '已调查'"
          />
        </template>
      </table-list>
      <pagination
        :page="page"
        @pageSizeChange="pageSizeChange"
        @pageCurrentChange="pageCurrentChange"
      />
    </el-card>
  </div>
</template>
<script>
import ToolsBtn from "../../components/Tools/ToolsBtn";
import TableList from "../../components/Table/TableList";
import TableProps from "../../utils/tableProps.js";
import Pagination from "../../components/Pagination/pagination";
import PageProps from "../../utils/pageProps.js";
import Hnew from "./Hnewsurvey"
export default {
  name: "NewSurvey",
  components: {
    ToolsBtn,
    TableList,
    Pagination
  },
  data() {
    return {
      table: TableProps,
      page: PageProps,
      toolsData: {
        title: "新建环保调查",
        datatimefier: false,
        datatime: '',
        identifier: false,
        content: "请输入设备号",
        query: '',
        oBtnShow: [
          { btn0: false }, // 新增按钮
          { btn1: false }, // 刷新按钮
          { btn2: false }, // 搜索按钮
          { btn3: false }, // 设置按钮
          { btn4: false } // 导出Excel按钮
        ]
      },
      userId: JSON.parse(sessionStorage.getItem("token")).userId,
      userlevel: JSON.parse(sessionStorage.getItem("token")).userlevel
    }
  },
  created(){
    this.table.tHead = Hnew;
    this.table.identifier = false;
    this.table.hasOperation = false;
    this.getList(1,10)
  },
  methods: {
    getList(pageNo, size){
      this.table.data = [];
      this.table.loading = true;
      var params = {}
      if(this.userlevel === 0){
        params = {
          pageNo,
          size,
        }
      } else {
         params = {
          pageNo,
          size,
          userid: this.userId
        }
      }
      this.$api.LAWMONITORING.NEWSURVEY(params)
      .then(res => {
        this.table.data = res.data;
        this.page.total = res.count;
        this.table.loading = false;
      })
      .catch(() => {
        this.$message({
          showClose: true,
          message: '暂无数据',
          type: 'error'
        });
      })
    },
    //编辑
    handleEdit(){},
    // 删除
    handleSee(){},
    fileSuccess(){
      this.$message({
        showClose: true,
        message: '上传成功',
        type: 'error'
      });
    },
    // 分页大小
    pageSizeChange(size) {
      // console.log(`每页 ${size} 条`);
      const tableDataLength = this.table.data.length;
      this.page.pageSize = size;
      if (tableDataLength < this.page.pageSize) {
        this.getList(1, size);
      } else {
        const pageNo = this.page.currentPage;
        this.getList(pageNo, size);
      }
    },
    // 翻页
    pageCurrentChange(pageNo) {
      // console.log(`当前页: ${pageNo}`);
      this.page.currentPage = pageNo;
      const size = this.page.pageSize;
      this.getList(pageNo, size);
    },
    // 新增数据
    addData() {
      // console.log("新 增");
      this.handleEdit();
    },
    // 列表数据刷新
    refresh() {
      // console.log("刷 新");
      this.getList(1,50)
    },
    // 搜索
    search() {
      this.searchDialog.visible = true;
      // console.log("搜索");
    },
     // 字段设置
    fieldSet() {
      // console.log("字段设置");
    },
    // 隐藏表格操作列
    hasOperation() {
      // console.log("隐藏表格操作列");
      this.table.hasOperation = !this.table.hasOperation;
    }
  }
}
</script>
<style lang="scss" scoped>
</style>


